<!DOCTYPE html>
<html lang="en" class="page-fill" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加单号规则</title>
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/css/oksub.css">
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script type="text/javascript" src="/lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form" lay-filter="filter">

        <input type="hidden" name="id" >

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入备注" id="remark" class="layui-textarea"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="edit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>
</div>

<!--js逻辑-->
<script src="/lib/layui/layui.js"></script>
<script>

    var initData;
    //设置标签，判断初始值是否已经赋值过了

    var isshow = false;

    function initForm(data) {
        var jsonString = JSON.stringify(data);
        initData = JSON.parse(jsonString);
        // console.info("1--->"+initData.data);
        //console.info("1--->"+initData)由该语句和下面的输出语句可知，initForm方法和layui.use有执行先后顺序问题
        //！isshow为true时，证明该方法先执行，在该方法内赋初始值
        if (!isshow) {
            initView(initData);
        }
    }

    function initView(initData) {
        console.log(initData);
        //赋初始值，注意隐藏域也要赋值
        layui.use(["jquery", "form"], function () {
            var form = layui.form;
            // 把所属网点赋值到input隐藏框中
            form.val("filter", initData);
        });
        //将isshow重置为true，说明初始值已经赋值过了
        isshow = true;
    }

    layui.use(["element", "form", "laydate", "okLayer", "okUtils","jquery"], function () {
        var form = layui.form;
        var okLayer = layui.okLayer;
        var okUtils = layui.okUtils;
        var $ = layui.jquery;
        okLoading.close();
        //console.info("2--->"+initData)
        //！isshow为true时，并且initData!=null&&initData!=undefined时，证明该方法先执行，在该方法内赋初始值
        if (!isshow && initData!=null&&initData!=undefined) {
            initView(initData);
        }
        form.on("submit(edit)", function (data) {

            console.info(data.field);
            okUtils.ajax("/api/orderNumberList/update", "post", data.field, true).done(function (response) {
                console.log(response);
                okLayer.greenTickMsg("操作成功", function () {
                    // 刷新父页面  window.parent.opener.location.reload();
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                console.log(error);
            });
            return false;
        });
    });
</script>
</body>
</html>